from typing import List

class Solution(object):
    def reverse(self, x: int) -> int:
        if x == 0:
            return 0
        op = True
        if x < 0:
            op = False
        s = str(abs(x))
        re = ''
        for ele in s:
            re = ele + re
        num = int(re)
        if num.bit_length() >= 32:
            return 0
        if not op:
            num = -num
        return num

    def reverse2(self, x: int) -> int:
        rev = int(str(abs(x))[::-1])
        return (-rev if x < 0 else rev) if rev.bit_length() < 32 else 0



if __name__=="__main__":
    solution = Solution()
    print(solution.reverse(1534236469))
    print(solution.reverse(-321))